<template>
  <div >
	  <body>
     <div  class="form-style-pri">
		 	<div id="printMe" v-html="nowHtml">
				
			 </div>
             <div style="display:flex;justify-content:center">
				  <!-- <el-button type="primary" @click="submitReport">保存报告</el-button> -->
				  <el-button type="success"  @click="back">返回</el-button>
				  <el-button type="primary" v-print="'#printMe'">打印报告</el-button>
			 </div>


			  <!-- <button @click="submitReport">保存报告</button> -->
			   <!-- <div v-print="'#printMe'">打印</div> -->
     </div>
         <!-- <div v-print="'#printMe'">打印</div>
		  <button @click="submitData">提交</button>-->
	  </body>
  </div>
</template>

<script>

import $ from "jquery"
import checkPermission from '@/utils/permission'
import { parseTime } from '@/utils/index'
import { report ,addReport} from '@/api/loanManageInfo'

export default {
  name: 'HomeIndex',
  components: {
   
  },
  data(){
    return {
	  loading:true,
	  
	  name1:"",
	  custNum:'',
	  custName:'',
	  moneyUseMethod:null,
	  content:'',
	  nowHtml:"",
		form:{
		//	busiType:"授信后业务",
		//	custKind:"授信后客户",
			id:"560fb621075311eabddefe22af050d33"
		},

		subForm:{
			reportData:null,
            taskId:"560fb621075311eabddefe22af050d33"
		}
    }
  },
  created(){
	  	setTimeout(() => {
			//  this.form.busiType = sessionStorage.getItem('busiTypeTask')
			 // this.form.custKind = sessionStorage.getItem('custKindTask')
			//  this.form.id = sessionStorage.getItem('idTask')
			 this.form.id = sessionStorage.getItem('viewReportId')
              report(this.form).then(res => {
		    	 this.nowHtml = res
					setTimeout(() => {
						this.loading = false
					}, 170)
				}).catch(err => {
					this.loading = false
           
               })
		}, 500)
	    //  report(this.form).then(res => {
		// 	 this.nowHtml = res
		// 	setTimeout(() => {
        //         this.loading = false
        //      }, 170)
        //   }).catch(err => {
        //     this.loading = false
           
        //   })
	

  },
  mounted(){
	  console.log($)
  },
  methods:{
	  parseTime,
     checkPermission,
     submitData(){
		 console.log('custNum', this.custNum)
		 console.log('custName', this.custName)
		  console.log('moneyUseMethod', this.moneyUseMethod)
		 this.content =document.getElementById('sharehoder').innerHTML
		 console.log('content',this.content) 
		  
	 },
	back(){
		 this.$router.go(-1)
	},
	 getAllTable(onetable){
		  var tabData=[];

			console.log(onetable)
			$(onetable).children("tbody").children("tr").each(function(trindex,tritem){
				console.log(tritem)
				var rowObj={};
				$(tritem).children("td").each(function(tdindex,tditem){
					var val=$(tditem).find("input").val();
					var key=$(tditem).find("input").attr("key");
					rowObj[key]=val;
				});
				tabData.push(rowObj);
			})
			return tabData


		
	 },
	 submitForm(){
		 console.log("提交")
	 },
	  submitReport(){
			var d= {}
			
			var t = $("#reportForm").serializeArray()
			// console.log(t)
			t.forEach(item=>{
				d[item.name]=item.value
				// console.log('item.value',item.value)
			})
			console.log($(".datalist-testList"))
			// console.log(d)
			// console.log(tabData)
			let table1 = {}
			let tableList = $(".datalist-testList")
			console.log(tableList)
			tableList.each((key,item)=>{
				let onelist =this.getAllTable(item)
				let newkey = $(item).attr("key")
				table1[newkey]= onelist
			})
			console.log(table1)
            //  d[newkey] = tabData
		     this.subForm.reportData = table1;
			 for(var j in d){
				 this.subForm.reportData[j] = d[j]
			 }
             this.subForm.taskId = sessionStorage.getItem('editReportId')
				addReport(this.subForm).then(res => {
						this.$router.go(-1)
						//this.$message.success('报告保存成功！')
                        this.$notify({
							title: '报告保存成功！',
							type: 'success',
							duration: 2500
						})
						setTimeout(() => {
							this.loading = false
						}, 170)
				}).catch(err => {
				this.loading = false
			
			    })
		}
	 	
			
			
  }
} 
</script>

<style  scoped>
 
  
</style>